package com.jg.locator;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.springframework.stereotype.Service;

@Service
public class EJBLocator {

	private final static String INITIAL = "org.jnp.interfaces.NamingContextFactory";
	private final static String URL = "org.jboss.naming:org.jnp.interfaces";
	private final static String PROVIDER = "localhost:1099";

	public Context getContext() {
		Properties p = new Properties();
		p.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL);
		p.put(Context.URL_PKG_PREFIXES, URL);
		p.put(Context.PROVIDER_URL, PROVIDER);

		try {
			return new InitialContext(p);
		} catch (NamingException ex) {
			System.out.println("Erro ");
			ex.printStackTrace();
			return null;
		}
	}
	
	public Object getEJB(String jndi){
		try {
			return getContext().lookup(jndi);
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();	 
		}
		
		return null;
	}

	
	
	
	
	
	
	
	
	
	
}
